package com.lyy.king.auth.controller;

import com.lyy.king.auth.modal.UserDTO;
import com.lyy.king.auth.model.request.LoginRequest;
import com.lyy.king.auth.model.response.LoginResponse;
import com.lyy.king.auth.service.AuthService;
import com.lyy.king.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: springcloud-learning
 * @BelongsPackage: com.cdx.auth.controller
 * @Author: cdx
 * @CreateTime: 2022-06-05  15:38
 * @Description:
 * @Version: 1.0
 */
@RestController
public class AuthController {
    @Autowired
    private AuthService authService;

    /**
     * 登录，返回token
     * @param request
     * @return
     */
    @PostMapping("/login")
    public Result<LoginResponse> login(@RequestBody LoginRequest request){
        LoginResponse response = authService.login(request);
        return Result.succcess(response);
    }

    /**
     * 退出登录
     * @return
     */
    @PostMapping("/logout")
    public Result logout(){
        return Result.succcess(authService.logout());
    }

    /**
     * 获取登录用户
     * @return
     */
    @GetMapping("/getLoginUserInfo")
    public Result<UserDTO> getTokenLoginInfo(){
        return Result.succcess(authService.getTokenLoginInfo());
    }

    @PostMapping("/checkToken")
    public Result<Boolean> checkToken(@RequestParam("token") String token){
        return Result.succcess(authService.checkToken(token));
    }


}
